package com.zygh.policeasset.service;

import cn.hutool.core.date.DateUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zygh.policeasset.mapper.AuditFlowMapper;
import com.zygh.policeasset.mapper.FinalStatementMapper;
import com.zygh.policeasset.mapper.UploadFileMapper;
import com.zygh.policeasset.pojo.FinalStatement;
import com.zygh.policeasset.pojo.Project;
import com.zygh.policeasset.pojo.ProjectNameType;
import com.zygh.policeasset.pojo.Section;
import com.zygh.policeasset.pojo.TableType;
import com.zygh.policeasset.pojo.UploadFile;
import com.zygh.policeasset.utils.AuditUtil;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
/* loaded from: police-asset-2.0-0.0.1-SNAPSHOT.jar:BOOT-INF/classes/com/zygh/policeasset/service/FinalStatementService.class */
public class FinalStatementService {
    @Autowired
    FinalStatementMapper finalStatementMapper;
    @Autowired
    UploadFileMapper uploadFileMapper;
    @Autowired
    AuditFlowMapper auditFlowMapper;
    @Autowired
    AuditFlowService auditFlowService;

    public PageInfo findAll(String name, Integer status, Integer companyId, Integer pageNum, Integer pageSize, String time1, String time2, Integer category, Integer userId) {
        PageHelper.startPage(pageNum.intValue(), pageSize.intValue());
        return new PageInfo<>(this.finalStatementMapper.findAll(name, status, companyId, time1, time2, category, userId));
    }

    public FinalStatement findById(Integer id) {
        return this.finalStatementMapper.findById(id);
    }

    public List<FinalStatement> findByProjectNoPage(String no) {
        return this.finalStatementMapper.findByProject(no);
    }

    public List<ProjectNameType> selectBytype() {
        return this.finalStatementMapper.selectBytype();
    }

    public Integer findCount() {
        return this.finalStatementMapper.findCount();
    }

    public List<ProjectNameType> findSectionByType(String projectNo) {
        return this.finalStatementMapper.findSectionByType(projectNo);
    }

    public PageInfo findByStatus(int status, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        return new PageInfo<>(this.finalStatementMapper.findByStatus(status));
    }

    public List<Project> getProject(Integer userId) {
        return this.finalStatementMapper.getProject(userId);
    }

    public List<Section> getAdd(String projectNo, Integer userId) {
        return this.finalStatementMapper.getAdd(projectNo, userId);
    }

    public Integer add(FinalStatement finalStatement) {
        String now = DateUtil.now();
        String flowNo = AuditUtil.getFlowNo(now);
        finalStatement.setFlowNo(flowNo);
        int finalStatementId = 0;
        try {
            finalStatement.setCreateTime(now);
            this.finalStatementMapper.add(finalStatement);
            finalStatementId = finalStatement.getId();
            this.auditFlowService.add(finalStatement.getUserId(), flowNo, now, TableType.FINALSTATEMENT.getName(), TableType.FINALSTATEMENT.getType(), finalStatement.getProjectNo(), finalStatement.getSectionId());
            for (UploadFile uploadFile : finalStatement.getUploadFileList()) {
                uploadFile.setProjectId(finalStatementId);
                uploadFile.setProjectName("final_statement");
                uploadFile.setCreateDate(DateUtil.now());
                this.uploadFileMapper.add(uploadFile);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Integer.valueOf(finalStatementId);
    }

    public Integer update(FinalStatement params) {
        return this.finalStatementMapper.update(params);
    }

    public Integer remove(int id) {
        int res = 0;
        try {
            res = this.finalStatementMapper.remove(id).intValue();
            this.uploadFileMapper.delete(id, "final_statement");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Integer.valueOf(res);
    }

    public int updateStatusAssets(String assetNewStatus, String projectNo, Integer sectionId) {
        return this.finalStatementMapper.updateStatusAssets(assetNewStatus, projectNo, sectionId);
    }

    public Integer updateStatus(int id, int status) {
        return this.finalStatementMapper.updateStatus(id, status);
    }

    public List<FinalStatement> toExcel(Integer id, String name, String companyId, String time1, String time2) {
        return this.finalStatementMapper.toExcel(id, name, companyId, time1, time2);
    }
}